package com.brillilab.service.core.instrument.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.brillilab.dao.mapper.instrument.InstrumentAccessMemberMapper;
import com.brillilab.domain.po.instrument.InstrumentAccessMember;
import com.brillilab.service.core.instrument.IInstrumentAccessMemberService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 仪器可使用组 服务实现类
 * </p>
 *
 * @author WuMenghao
 * @since 2019-06-12
 */
@Service
@Transactional
public class InstrumentAccessMemberServiceImpl implements IInstrumentAccessMemberService {

    @Resource
    private InstrumentAccessMemberMapper instrumentAccessMemberMapper;

    @Override
    public List<InstrumentAccessMember> selectList(Long groupId) {
        return instrumentAccessMemberMapper.selectList(
                new LambdaQueryWrapper<InstrumentAccessMember>()
                        .eq(InstrumentAccessMember::getAccessGroupId,groupId));
    }

    @Override
    public int insertBatch(List<InstrumentAccessMember> accessMembers) {
        if(CollectionUtils.isNotEmpty(accessMembers)){
            return instrumentAccessMemberMapper.insertBatch(accessMembers);
        }
        return 0;
    }

    @Override
    public boolean delete(Long accessGroupId) {
        return instrumentAccessMemberMapper.delete(
                new LambdaQueryWrapper<InstrumentAccessMember>()
                        .eq(InstrumentAccessMember::getAccessGroupId,accessGroupId)) >=0;
    }
}
